package com.example.sunhetian.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.sunhetian.entity.Dept;
import com.example.sunhetian.service.IDeptService;
import com.example.sunhetian.util.Result;
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.management.Query;
import java.util.Collection;
import java.util.Date;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author ykg
 * @since 2022-12-28
 */
@ResponseBody
@RestController
@RequestMapping("/dept")

public class DeptController {
    @GetMapping("my1")
    public String my1(){

        return "9999";

    }
    @Resource
    private IDeptService iDeptService;
    @GetMapping
    public Result getAll(){
        List<Dept> list=iDeptService.list();
        return new Result(list);
    }

    @GetMapping("getAlldept")
    public Result getAlldept(Integer curr, Integer size, String loc, String dname, String six,String date){
        Page page=new Page(curr,size);
        QueryWrapper queryWrapper=new QueryWrapper();
        if (StringUtils.isNoneBlank(loc)){
            queryWrapper.like("loc",loc);

        }
        if (StringUtils.isNoneBlank(dname)){
            queryWrapper.like("dname",dname);

        }
        if (StringUtils.isNoneBlank(six)){
            queryWrapper.like("six",six);

        }
        if (StringUtils.isNotBlank(date)){
            if(!date.equals("null")){
                queryWrapper.like("date",date);
            }

        }
        Page list=iDeptService.page(page,queryWrapper);

        return new Result(list);
    }
    /**删除**/
    @DeleteMapping("{deptno}")
    public Result delByid(@PathVariable Integer deptno){
        return new Result(iDeptService.removeById(deptno));
    }

    @PostMapping
    public  Result addOrUpdate(Dept dept){
        return  new Result(iDeptService.saveOrUpdate(dept));
    }



}

